package com.xiaoyu.lanling.feature.chat.data.emoji

import com.xiaoyu.lanling.feature.chat.model.emoji.ChatEmojiGridItem
import com.xiaoyu.lanling.feature.chat.model.emoji.ChatEmojiGridItem.Companion.create
import io.reactivex.Single
import io.reactivex.SingleEmitter
import java.util.*

object ChatEmojiData {

    private val chatEmojiList = ArrayList<ChatEmojiGridItem>()

    @JvmStatic
    fun createChatEmojiList(): Single<ArrayList<ChatEmojiGridItem>?> {
        return Single.create { emitter: SingleEmitter<ArrayList<ChatEmojiGridItem>?> ->
            if (chatEmojiList.isEmpty()) {
                loadData()
            }
            emitter.onSuccess(chatEmojiList)
        }
    }

    private fun loadData() {
        chatEmojiList.add(create(fromCodePoint(0x1f604)))
        chatEmojiList.add(create(fromCodePoint(0x1f60a)))
        chatEmojiList.add(create(fromChar(0x263a.toChar())))
        chatEmojiList.add(create(fromCodePoint(0x1f609)))
        chatEmojiList.add(create(fromCodePoint(0x1f60d)))
        chatEmojiList.add(create(fromCodePoint(0x1f618)))
        chatEmojiList.add(create(fromCodePoint(0x1f61a)))
        chatEmojiList.add(create(fromCodePoint(0x1f619)))
        chatEmojiList.add(create(fromCodePoint(0x1f61c)))
        chatEmojiList.add(create(fromCodePoint(0x1f61d)))
        chatEmojiList.add(create(fromCodePoint(0x1f633)))
        chatEmojiList.add(create(fromCodePoint(0x1f601)))
        chatEmojiList.add(create(fromCodePoint(0x1f614)))
        chatEmojiList.add(create(fromCodePoint(0x1f60c)))
        chatEmojiList.add(create(fromCodePoint(0x1f612)))
        chatEmojiList.add(create(fromCodePoint(0x1f61e)))
        chatEmojiList.add(create(fromCodePoint(0x1f623)))
        chatEmojiList.add(create(fromCodePoint(0x1f602)))
        chatEmojiList.add(create(fromCodePoint(0x1f62d)))
        chatEmojiList.add(create(fromCodePoint(0x1f62a)))
        chatEmojiList.add(create(fromCodePoint(0x1f625)))
        chatEmojiList.add(create(fromCodePoint(0x1f605)))
        chatEmojiList.add(create(fromCodePoint(0x1f613)))
        chatEmojiList.add(create(fromCodePoint(0x1f629)))
        chatEmojiList.add(create(fromCodePoint(0x1f628)))
        chatEmojiList.add(create(fromCodePoint(0x1f631)))
        chatEmojiList.add(create(fromCodePoint(0x1f620)))
        chatEmojiList.add(create(fromCodePoint(0x1f621)))
        chatEmojiList.add(create(fromCodePoint(0x1f624)))
        chatEmojiList.add(create(fromCodePoint(0x1f606)))
        chatEmojiList.add(create(fromCodePoint(0x1f60b)))
        chatEmojiList.add(create(fromCodePoint(0x1f637)))
        chatEmojiList.add(create(fromCodePoint(0x1f60e)))
        chatEmojiList.add(create(fromCodePoint(0x1f634)))
        chatEmojiList.add(create(fromCodePoint(0x1f632)))
        chatEmojiList.add(create(fromCodePoint(0x1f61f)))
        chatEmojiList.add(create(fromCodePoint(0x1f608)))
        chatEmojiList.add(create(fromCodePoint(0x1f62e)))
        chatEmojiList.add(create(fromCodePoint(0x1f60f)))
        chatEmojiList.add(create(fromCodePoint(0x1f611)))
        chatEmojiList.add(create(fromCodePoint(0x1f648)))
        chatEmojiList.add(create(fromCodePoint(0x1f649)))
        chatEmojiList.add(create(fromCodePoint(0x1f64a)))
        chatEmojiList.add(create(fromCodePoint(0x1f4a9)))
        chatEmojiList.add(create(fromCodePoint(0x1f525)))
        chatEmojiList.add(create(fromChar(0x2728.toChar())))
        chatEmojiList.add(create(fromCodePoint(0x1f4a4)))
        chatEmojiList.add(create(fromCodePoint(0x1f4a8)))
        chatEmojiList.add(create(fromCodePoint(0x1f440)))
        chatEmojiList.add(create(fromCodePoint(0x1f44d)))
        chatEmojiList.add(create(fromCodePoint(0x1f44e)))
        chatEmojiList.add(create(fromCodePoint(0x1f44c)))
        chatEmojiList.add(create(fromCodePoint(0x1f44a)))
        chatEmojiList.add(create(fromChar(0x270c.toChar())))
        chatEmojiList.add(create(fromCodePoint(0x1f446)))
        chatEmojiList.add(create(fromCodePoint(0x1f447)))
        chatEmojiList.add(create(fromCodePoint(0x1f449)))
        chatEmojiList.add(create(fromCodePoint(0x1f448)))
        chatEmojiList.add(create(fromCodePoint(0x1f64c)))
        chatEmojiList.add(create(fromCodePoint(0x1f64f)))
        chatEmojiList.add(create(fromCodePoint(0x1f44f)))
        chatEmojiList.add(create(fromCodePoint(0x1f4aa)))
        chatEmojiList.add(create(fromCodePoint(0x1f48f)))
        chatEmojiList.add(create(fromCodePoint(0x1f491)))
        chatEmojiList.add(create(fromCodePoint(0x1f646)))
        chatEmojiList.add(create(fromCodePoint(0x1f645)))
        chatEmojiList.add(create(fromCodePoint(0x1f481)))
        chatEmojiList.add(create(fromCodePoint(0x1f64b)))
        chatEmojiList.add(create(fromCodePoint(0x1f486)))
        chatEmojiList.add(create(fromCodePoint(0x1f451)))
        chatEmojiList.add(create(fromChar(0x2764.toChar())))
        chatEmojiList.add(create(fromCodePoint(0x1f494)))
        chatEmojiList.add(create(fromCodePoint(0x1f497)))
        chatEmojiList.add(create(fromCodePoint(0x1f496)))
        chatEmojiList.add(create(fromCodePoint(0x1f48b)))
        chatEmojiList.add(create(fromCodePoint(0x1f48e)))
        chatEmojiList.add(create(fromCodePoint(0x1f436)))
        chatEmojiList.add(create(fromCodePoint(0x1f431)))
        chatEmojiList.add(create(fromCodePoint(0x1f437)))
        chatEmojiList.add(create(fromCodePoint(0x1f412)))
        chatEmojiList.add(create(fromCodePoint(0x1f43c)))
        chatEmojiList.add(create(fromCodePoint(0x1f490)))
        chatEmojiList.add(create(fromCodePoint(0x1f338)))
        chatEmojiList.add(create(fromCodePoint(0x1f340)))
        chatEmojiList.add(create(fromCodePoint(0x1f339)))
        chatEmojiList.add(create(fromCodePoint(0x1f31d)))
        chatEmojiList.add(create(fromCodePoint(0x1f31a)))
        chatEmojiList.add(create(fromCodePoint(0x1f49d)))
        chatEmojiList.add(create(fromCodePoint(0x1f47b)))
        chatEmojiList.add(create(fromCodePoint(0x1f381)))
        chatEmojiList.add(create(fromCodePoint(0x1f389)))
        chatEmojiList.add(create(fromCodePoint(0x1f382)))
        chatEmojiList.add(create(fromCodePoint(0x1f36d)))
    }

    private fun fromCodePoint(codePoint: Int): String {
        return newString(codePoint)
    }

    private fun fromChar(ch: Char): String {
        return Character.toString(ch)
    }

    private fun newString(codePoint: Int): String {
        return if (Character.charCount(codePoint) == 1) {
            codePoint.toString()
        } else {
            String(Character.toChars(codePoint))
        }
    }
}